/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 

package com.sui.bigdata.flink.sql.core.source;


import com.sui.bigdata.flink.sql.core.table.AbsSourceParser;
import com.sui.bigdata.flink.sql.core.table.SourceTableInfo;
import com.sui.bigdata.flink.sql.source.kafka.KafkaSource;
import com.sui.bigdata.flink.sql.source.kafka.table.KafkaSourceParser;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.java.StreamTableEnvironment;

/**
 * streamTableSource
 * Date: 2019/07/10
 * @author yong_chen@sui.com
 */

public class StreamSourceFactory {

    private static final String TYPE ="target";

    private static final String KAFKA = "kafka";

    public static AbsSourceParser getSqlParser(String pluginType) throws Exception {
        switch (pluginType){
            case KAFKA:
                return new KafkaSourceParser();
            default:
                throw new RuntimeException(" not support this source now ");
        }
    }

    /**
     * The configuration of the type specified data source
     * @param sourceTableInfo
     * @return
     */
    public static Table getStreamSource(SourceTableInfo sourceTableInfo, StreamExecutionEnvironment env,
                                        StreamTableEnvironment tableEnv,int envParallelism) throws Exception {
        IStreamSourceGener sourceGener;
        Object object;
        switch (sourceTableInfo.getType()){
            case KAFKA:
                sourceGener = new KafkaSource();
                object = sourceGener.genStreamSource(sourceTableInfo, env, tableEnv,envParallelism);
                return (Table) object;
            default:
                throw new RuntimeException(" not support this source now ");
        }
    }

    public static void main(String[] args) throws Exception {

        String BLOOM_FILTER_NAME="kn_phonelabel:{kn_phonelabel}:adl_bd_ls";
        System.out.println("redis.call('HSET', KEYS[2],redis.call('HGET', KEYS[1]));redis.call('DEL',KEYS[1]); return 1;\" 2 "+BLOOM_FILTER_NAME+"_temp "+BLOOM_FILTER_NAME);
    }
}
